package vistas;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


import controladores.CargaJugador;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;


public class FormCargaNombre extends JDialog {
	
	private CargaJugador controlador;
	private int cantJugadores;
	private JPanel panel;
	private JLabel jLabel;
	private JButton jButtonOK;
	private JTextField jTextNombre;
	
	
	public FormCargaNombre(CargaJugador controlador) {
		super();
		this.controlador = controlador;
    	this.cantJugadores = 1;
		initGUI();
	}
	
	private void initGUI() {
		this.setSize(300, 130);
    	this.setLocation(400,350);
    	this.setResizable(false);
    	this.setTitle("INGRESE SU NOMBRE");        
    	
        this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        
        this.panel = new JPanel();
        
        this.jButtonOK = new JButton("OK");
        this.jButtonOK.setMnemonic(java.awt.event.KeyEvent.VK_A);
        this.jButtonOK.addActionListener(
        		new ActionListener(){
        			public void actionPerformed(ActionEvent e) {
        				jButtonOKMousePressed();
        			}
        		}
        	);
        
       /* this.btnFinalizar = new JButton("Finalizar");
        this.btnFinalizar.setMnemonic(java.awt.event.KeyEvent.VK_F);
        this.btnFinalizar.addActionListener(
        		new ActionListener(){
        			public void actionPerformed(ActionEvent e) {
        				btnFinalizarMousePressed();
        			}
        		}
        	);*/
        
        this.jTextNombre = new JTextField("Jugador",15);
        this.jTextNombre.selectAll();
        this.jTextNombre.addKeyListener(
        		new KeyAdapter(){
        			public void keyPressed(KeyEvent evento){
        				if (evento.getKeyChar()== KeyEvent.VK_ENTER )
        					jButtonOKMousePressed();
        			}
        		});
        
        this.jLabel = new JLabel("Nombre del Jugador" );
        this.jLabel.setForeground(Color.blue);
        this.jLabel = new JLabel("");
        //this.lblError.setForeground(Color.RED);

        this.panel.add(jLabel);
        this.panel.add(jTextNombre);
        //this.panel.add(lblError);
        this.panel.add(jButtonOK);
        //this.panel.add(btnFinalizar);
        this.panel.setBackground(Color.cyan);
        
        this.add(panel);
	}
	
	private void cargarNombre() {
		controlador.agregarJugador(this.jTextNombre.getText());
	}
	
	public void ocultar(){
    	this.setVisible(false);
    }
	
	public void mostrar(){
    	this.setVisible(true);
    }
	
	private void jButtonOKMousePressed() {
		controlador.agregarJugador(this.jTextNombre.getText());
		FinalizarCarga();
		//botonPresionado();
    }
	
	private void FinalizarCarga() {
		controlador.finalizarCargaJugadores();
		//botonPresionado();
	}

}
